"""
可视化组件
"""
import streamlit as st
import pandas as pd
import plotly.express as px


def line_chart(data: pd.DataFrame, x: str, y: str, title: str = ""):
    """
    绘制折线图
    
    Args:
        data: 数据框
        x: x轴字段
        y: y轴字段
        title: 图表标题
    """
    fig = px.line(data, x=x, y=y, title=title)
    st.plotly_chart(fig, use_container_width=True)


def bar_chart(data: pd.DataFrame, x: str, y: str, title: str = ""):
    """
    绘制柱状图
    """
    fig = px.bar(data, x=x, y=y, title=title)
    st.plotly_chart(fig, use_container_width=True)


def pie_chart(data: pd.DataFrame, names: str, values: str, title: str = ""):
    """
    绘制饼图
    """
    fig = px.pie(data, names=names, values=values, title=title)
    st.plotly_chart(fig, use_container_width=True)


def metric_card(title: str, value, delta=None):
    """
    指标卡片
    """
    st.metric(title, value, delta)